package com.tongshu.naive.chat.socket;

import codec.ObjEncoder;
import com.tongshu.naive.chat.application.UIService;
import com.tongshu.naive.chat.socket.handler.*;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

import codec.ObjDecoder;

public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
    private UIService uiService;

    public MyChannelInitializer(UIService uiService) {
        this.uiService = uiService;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        // 对象传输处理【解码】
        socketChannel.pipeline().addLast(new ObjDecoder());
        // 在管道中添加我们自己的接收数据实现方法
        socketChannel.pipeline().addLast(new AddFriendHandler(uiService));
        socketChannel.pipeline().addLast(new LoginHandler(uiService));
        socketChannel.pipeline().addLast(new MsgGroupHandler(uiService));
        socketChannel.pipeline().addLast(new MsgHandler(uiService));
        socketChannel.pipeline().addLast(new SearchFriendHandler(uiService));
        socketChannel.pipeline().addLast(new TalkNoticeHandler(uiService));
        // ...
        // 对象传输处理[编码]
        socketChannel.pipeline().addLast(new ObjEncoder());
    }
}
